Show:

CGSGSceneGraph Class

Extends Object
Module: Scene

Represent the scene graph it self. It encapsulates the root node and list of timelines for animations

Constructor

CGSGSceneGraph
(
  • canvas
  • context
)
Parameters:
  • canvas HTMLElement

    a handler to the canvas HTML element

  • context CanvasRenderingContext2D

    context to render on

Methods

addAnimationKey
(
  • node
  • attribute
  • frame
  • value
  • method
  • precompute
)

Add a key

Parameters:
  • node CGSGNode

    handler to the nodes to animate

  • attribute String

    String representing the attribute to animate ("position.y", "rotation.angle", "fill", ...)

  • frame Number

    the date for the key

  • value Number

    value for the attribute at the frame

  • method String

    animation method. Must be 'linear' for now

  • precompute Boolean

    Set to true if you want to precompute the animations steps

Example:

this.sceneGraph.addAnimation(imgNode, "position.x", 2000, 200, "linear", true);

addNode
(
  • node
  • parent
)

Add a nodes on the scene. If the root does not already exist, this nodes will be used as root

Parameters:
  • node CGSGNode

    the nodes to add

  • parent CGSGNode

    the parent nodes of the new one. If it's null, the root will be used as nodes.

animate
(
  • node
  • attribute
  • duration
  • from
  • to
  • method
  • delay
  • precompute
)

Animate an attribute of a nodes

Parameters:
  • node CGSGNode

    Handler to the nodes to animate

  • attribute String

    String representing the attribute to animate ("position.y", "rotation.angle", "fill", ...)

  • duration Number

    Duration of the animation, in frame

  • from Number

    Start value

  • to Number

    End value

  • method String

    Animation method. Must be 'linear' for now

  • delay Number

    Delay before start the animation, in frames

  • precompute Boolean

    Set to true if you want to precompute the animations steps

Example:

this.sceneGraph.animate(imgNode, "position.x", 700, 0, 200, "linear", 0, true);

deselectAll
(
  • excludedArray
)

Mark all nodes as not selected

Parameters:
  • excludedArray Array

    CGSGNodes to not deselect

deselectNode
(
  • nodeToDeselect
)

Mark the nodes as not selected

Parameters:
getTimeline
(
  • node
  • attribute
)
CGSGTimeline

Return the timeline corresponding with the nodes and attribute. Create it if does not exists yet

Parameters:
  • node CGSGNode

    Handle to the nodes

  • attribute String

    String. the attribute name

Returns:
initializeGhost
(
  • width
  • height
)
private

Initialize the ghost rendering, used by the PickNode function

Parameters:
  • width Number

    The width for the canvas. Must be the same as the rendering canvas

  • height Number

    The height for the canvas. Must be the same as the rendering canvas

pickNode
(
  • mousePosition
  • condition
)
CGSGNode

Recursively traverse the nodes and return the one who is under the mouse coordinates

Parameters:
Returns:
Example:

this.scenegraph.picknode(mousePosition, 'position.x > 100');
this.scenegraph.picknode(mousePosition, 'position.x > 100 && this.position.y > 100');

pickNodes
(
  • region
  • condition
)
Array

Recursively traverse the nodes and return the ones who are under the mouse coordinates

Parameters:
Returns:
Example:

this.scenegraph.picknodes(region, 'position.x > 100');
this.scenegraph.picknodes(region, 'position.x > 100 && this.position.y > 100');

removeNode
(
  • node
)
Boolean

Remove the child nodes passed in parameter, from the root nodes

Parameters:
Returns:
Boolean: true if the nodes was found and removed
render () public

Render the SceneGraph

selectNode
(
  • nodeToSelect
)

Mark the nodes as selected so the select marker (also called selectedHandlers) will be shown and the SceneGraph will manage the moving and resizing of the selected objects.

Parameters:
  • nodeToSelect Object

    The CGSGNode to be selected

setCanvasDimension
(
  • newDimension
)

Change the dimension of the canvas. Does not really change the dimension of the rendering canvas container, but is used for different computations

Parameters:
stillHaveAnimation () Boolean
Returns:
Boolean: true if there are still animation key after the current frame

Properties

_listTimelines Array private

List of the timelines for the animations. A timeline consists of a list of animation keys for 1 attribute of the nodes

_nextNodeID Number private
context CanvasRenderingContext2D
ghostCanvas HTMLElement

Initialize a ghost canvas used to determine which nodes are selected by the user

root CGSGNode

Root node of the graph

selectedNodes Array

The nodes currently selected by the user